﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Windows.Controls;

namespace WpfApplication1
{
    /// <summary>
    /// Window1.xaml の相互作用ロジック
    /// </summary>
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            IInputElement focusedElement = FocusManager.GetFocusedElement(this);
            if (e.Key == Key.Enter)
            {
                if (focusedElement.GetType() == typeof(TextBox) || focusedElement.GetType() == typeof(ComboBox) || focusedElement.GetType() == typeof(DataGridCell) || focusedElement.GetType() == typeof(Button))
                //if (focusedElement.GetType() == typeof(TextBox) && (focusedElement as Control).Name != "txtSkBox")
                {
                    KeyEventArgs e1 = new KeyEventArgs(Keyboard.PrimaryDevice, Keyboard.PrimaryDevice.ActiveSource,0, Key.Tab);
                    e1.RoutedEvent = Keyboard.KeyDownEvent;
                    InputManager.Current.ProcessInput(e1);
                    if (focusedElement.GetType() != typeof(Button))
                    {
                        e.Handled = true;
                    }
                }
            }
            if (e.Key == Key.Tab)
            {
                if (focusedElement.GetType() == typeof(DataGridCell))
                {
                    //Tab押下遷移を記載
                }
            }
        }
    }
}
